#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for(register int i = (a);i <= (b);++i)
#define per(i,a,b) for(register int i = (a);i >= (b);--i)  
typedef long long ll;
typedef unsigned long long ull;
using std::string;using std::cin;using std::cout;

int n,m,x,y;
std::map<char,int>mp;
std::map<int,char>back;
char ch[20];

inline void out(int now){
    if(now){out(now/m);cout << back[now % m];}
}

int main(){
    std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("in.in", "r", stdin);
    mp['1'] = 1 , mp['2'] = 2 , mp['3'] = 3 , mp['4'] = 4 , mp['5'] = 5 ,
    mp['6'] = 6 , mp['7'] = 7 , mp['8'] = 8 , mp['9'] = 9 , mp['0'] = 0;
    mp['A'] = 10 , mp['B'] = 11 , mp['C'] = 12 ,
    mp['D'] = 13 , mp['E'] = 14 , mp['F'] = 15 ;
    back[1] = '1' , back[2] = '2' , back[3] = '3' , back[4] = '4' , back[5] = '5' ,
    back[6] = '6' , back[7] = '7' , back[8] = '8' , back[9] = '9' , back[0] = '0';
    back[10] = 'A' , back[11] = 'B' , back[12] = 'C' , back[13] = 'D' , back[14] = 'E' , back[15] = 'F';
    cin >> n;
    cin >> ch+1;
    int len = strlen(ch+1);
    rep(i,1,len){
        x = x * n + mp[ch[i]];
    }
    cin >> m;
    out(x);

    return 0;
}